package com.wcl.demo.ui.fragment;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.wcl.demo.R;


/**
 * Created by dllo on 15/11/17.
 */
public class PersonFragment extends Fragment implements View.OnClickListener {
    private TextView fragment_person_left_Tv, fragment_person_right_Tv, title_textView, ranking_tv;
    private FragmentManager fragmentManager;
    Fragment FriendsFragment = new FriendsFragment();
   // Fragment FriendFragment = new FriendFragment();
    Fragment GroupFragment = new GroupFragment();

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        return inflater.inflate(R.layout.fragment_person, container, false);
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        fragment_person_left_Tv = (TextView) getActivity().findViewById(R.id.fragment_person_left_Tv);
        fragment_person_right_Tv = (TextView) getActivity().findViewById(R.id.fragment_person_right_Tv);
        title_textView = (TextView) getActivity().findViewById(R.id.title_textView);
        fragment_person_left_Tv.setOnClickListener(this);
        fragment_person_right_Tv.setOnClickListener(this);
        fragmentManager = getActivity().getSupportFragmentManager();

        initfragment(FriendsFragment);//替换Fragemnt
    }

    //点击替button换fragment的方法
    public void initfragment(Fragment fragment) {
        FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
        fragmentTransaction.replace(R.id.friendView, fragment);
        fragmentTransaction.commit();
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.fragment_person_left_Tv:
                fragment_person_left_Tv.setBackgroundColor(getResources().getColor(R.color.person_tab_text_on));//左侧text背景设蓝
                fragment_person_left_Tv.setTextColor(getResources().getColor(R.color.person_tab_text_push));//左侧字体设白
                fragment_person_right_Tv.setBackgroundColor(getResources().getColor(R.color.person_tab_text_push));//右侧背景设白
                fragment_person_right_Tv.setTextColor(getResources().getColor(R.color.person_tab_text_on));//右侧字体设蓝
                title_textView.setText(fragment_person_left_Tv.getText());//更换标题头
                initfragment(FriendsFragment);//调用替换方法
                break;
            case R.id.fragment_person_right_Tv:
                fragment_person_left_Tv.setBackgroundColor(getResources().getColor(R.color.person_tab_text_push));//左侧背景设白
                fragment_person_right_Tv.setBackgroundColor(getResources().getColor(R.color.person_tab_text_on));//右侧背景设蓝
                fragment_person_left_Tv.setTextColor(getResources().getColor(R.color.person_tab_text_on));//左侧字体设蓝
                fragment_person_right_Tv.setTextColor(getResources().getColor(R.color.person_tab_text_push));//右侧字体设白
                title_textView.setText(fragment_person_right_Tv.getText());//更换标题头
                initfragment(GroupFragment);//调用替换方法
                break;

        }
    }



}
